﻿namespace LeetCodeProject._0001_1000._001_100._41_50._045;

public class Solution
{
    public int Jump(int[] nums)
    {
        if (nums.Length == 1)
            return 0;
        var pn = nums[0];
        var step = 1;
        var i = 1;
        while (i < nums.Length - 1)
        {
            if (pn >= nums.Length - 1)
                break;
            var pi = pn;
            while (i <= pi)
            {
                pn = Math.Max(i + nums[i], pn);
                i++;
            }

            step++;
            if (pn >= nums.Length - 1)
                break;
        }

        return step;
    }
}